<template>
    <div class="example">
        <span @click="toExpertDetail(38)">专家</span>
        <span @click="toInformationDetail(1046, '哈喽你好啊')">资讯详情</span>
        <span @click="goCourseDetail(61)">图文：课程详情</span>
        <span @click="goCourseDetail(59)">视频：课程详情</span>
        <span @click="goCourseDetail(1000)">无：课程详情</span><br/>
        <a href="studyshengxueonline://" target="_blank">打开app</a>
    </div>
</template>

<script>
export default {
    data(){
        return{}
    },
    methods:{
         //安卓,IOS方法
        isTerminal(){
            var u = navigator.userAgent;
            var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
            var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
            if (isAndroid) {
               return "isAndroid"
            } else if (isiOS) {
               return "isiOS"
            }
        },
        // 资讯详情
        toInformationDetail(id,title){
            let params={
                id: id,  //资讯的ID
                title: title  //资讯的title
            }
            if(this.isTerminal()=='isiOS'){
                window.webkit.messageHandlers.goNewsDetail.postMessage(params)
            }else{
                ZMParentsJsToAndroid.goNewsDetail(JSON.stringify(params))
            };
        },
        //跳转专家详情
        toExpertDetail(id){
            if(this.isTerminal()=='isiOS'){
                window.webkit.messageHandlers.goExpertsHomePage.postMessage(id)
            }else{
                ZMParentsJsToAndroid.goExpertsHomePage(id)
            };
        },
        // 课程详情
        goCourseDetail(id){
            if(this.isTerminal()=='isiOS'){
                window.webkit.messageHandlers.goCourseDetail.postMessage(id)
            }else{
                ZMParentsJsToAndroid.goCourseDetail(id)
            };
        }
    }
}
</script>

<style lang="scss">
    .example{
        padding: 15px;
        span{
            display: block;
            font-size: 22px;
            color: blue
        }
        a{
            font-size: 22px;
        }
    }
</style>
